import { onMounted, onBeforeUnmount } from "vue";
import eventBus from "../eventBus";

export default function (mainContainer) {
    function handleScroll() {
        eventBus.emit("mainScroll", mainContainer.value)
    }

    function scollTop(top) {
        mainContainer.value.scrollTop = top;
    }

    onMounted(() => {
        console.log("执行了吗", mainContainer.value)
        mainContainer.value.addEventListener("scroll", handleScroll);
        eventBus.on('scrollTop', scollTop)
    })

    onBeforeUnmount(() => {
        mainContainer.value.removeEventListener("scroll", handleScroll);
        eventBus.off('scrollTop', scollTop)
    })
}